<template>
  <section>
    <el-dialog
      title="提交审核"
      :visible.sync="open"
      width="600px"
      append-to-body
      @close="cancel"
      custom-class="audit-mode"
    >
      <Form
        v-if="auditUserList.length"
        :formData="formData"
        :rulesData="rulesData"
        :formBtns="formBtns"
        @handleSubmit="handleSubmit"
      />
    </el-dialog>
  </section>
</template>

<script>
import { Rule } from "@/utils/rule.js";
import Form from "@/components/form/index.vue";
export default {
  components: {
    Form,
  },
  props: {
    from: {
      type: String,
      default: "",
    },
    row: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      open: true,
      auditUserList: [],
      formData: [
        {
          prop: "nextAudit",
          type: "selectFilter",
          options: [],
          label: "下一节点审核",
          placeholder: "请输入下一节点审核",
          value: "",
        },
      ],
      formBtns: [
        //表单按钮
        {
          type: "primary",
          label: "保存",
          isVerify: true,
        },
        {
          label: "返回",
          click: () => {
            this.$emit("onBack", "isAudit");
          },
        },
      ],

      rulesData: {
        nextAudit: [
          Rule.checkDataNull("请输入下一节点审核", ["blur", "change"]),
        ],
        ld: [Rule.checkDataNull("请输入中心领导审核", "blur")],
      },
    };
  },

  created() {
    if (this.from === "plan" && this.row.status == 0) {
      this.formData.unshift({
        prop: "flag",
        type: "select",
        options: [
          { label: "是", value: 1 },
          { label: "否", value: 0 },
        ],
        label: "科室负责人",
        placeholder: "请选择科室负责人",
        value: 1,
      });
    }
    if (this.from === "tapRecord" && this.row.status == 0) {
      this.formData.unshift({
        prop: "flag",
        type: "select",
        options: [
          { label: "是", value: 1 },
          { label: "否", value: 0 },
        ],
        label: "监管员",
        placeholder: "请选择监管员",
        value: 1,
      });
    }
  },
  mounted() {
    this.getLoad();
  },
  methods: {
    //获取数据
    getLoad() {
      this.GetAuditUserList((data) => {
        data.forEach((item) => {
          item.label = item.userName;
          item.value = item.userId + "/" + item.userName;
        });
        this.auditUserList = data;
        if (
          (this.from === "tapRecord" && this.row.status == 0) ||
          (this.from === "plan" && this.row.status == 0)
        ) {
          this.formData[1].options = data;
          return;
        }
        this.formData[0].options = data;
      });
    },
    //保存
    handleSubmit(data) {
      this.$emit("onSuccess", data);
    },
    // 关闭模态框
    cancel() {
      this.$emit("onBack", "isAudit");
    },
  },
};
</script>

<style lang="scss">
@import "../../../assets/styles/collect.scss";
.audit-mode {
  .el-dialog__body {
    padding: 30px 20px 15px;
  }
  .form {
    margin-bottom: 0;
    .el-form-item {
      width: 100%;
      &:last-child {
        margin-bottom: 0 !important;
      }
    }
  }
}
</style>
